<?php

/**
 * product actions.
 *
 * @package    emc
 * @subpackage product
 * @author     Your name here
 * @version    SVN: $Id: actions.class.php 23810 2009-11-12 11:07:44Z Kris.Wallsmith $
 */
class productActions extends sfActions
{
 /**
  * Executes index action
  *
  * @param sfRequest $request A request object
  */
  public function executeIndex(sfWebRequest $request)
  {
    $this->forward('default', 'module');
  }


  public function executeList(sfWebRequest $request)
  {
    $marque_id = $request->getParameter('marque_id', null);
    if ($marque_id) {
      $marque = Doctrine_Core::getTable('Marque')->find($marque_id);
      $category_id = $marque->category_id;
    } else
      $category_id = $request->getParameter('category_id', null);
    if ($category_id) {
      $category = Doctrine_Core::getTable('Category')->find($category_id);
      if ($category->is_active) {
        $this->products = array();
        $category->getProducts($this->products);
      }

    }
  	/*$brand_id = $request->getParameter('brand_id', null);
  	$q = Doctrine_Query::create()
  			->select(  'p.id,
  						p.brand_id, 
  						p.name as product_name, 
  						p.discount_price, 
  						p.original_price, 
  						p.images, 
  						p.available, 
  						b.name as brand_name, 
  						c.name as catalog_name, 
  						m.name as marque_name, 
						e.name as category_name, 
  						j.name as jobboard_name')
  			->from('Product p')
  			->leftJoin('p.Brand b')
  			->leftJoin('b.Catalog c')
  			->leftJoin('c.Marque m')
			->leftJoin('m.Category e')
  			->leftJoin('m.Jobboard j');
  	if ($brand_id)
  		$q->addWhere('p.brand_id = ?', $brand_id);

  	$catalog_id = $request->getParameter('catalog_id', null);
  	if ($catalog_id)
  		$q->addWhere('c.id = ?', $catalog_id);

  	$marque_id = $request->getParameter('marque_id', null);
  	if ($marque_id)
  		$q->addWhere('m.id LIKE ?', $marque_id);

  	$jobboard_id = $request->getParameter('jobboard_id');
  	if ($jobboard_id)
  		$q->addWhere('j.id LIKE ?', $jobboard_id);
	
	$category_id = $request->getParameter('category_id');
  	if ($category_id)
  		$q->addWhere('e.id LIKE ?', $category_id);
	
  	$this->products = $q->fetchArray();
  	foreach ($this->products as $key => $product) {
  		$images = json_decode($product['images'], true);
  		$image = $images['thumb'];
  		$this->products[$key]['images'] = $image;
  	}*/

  	return sfView::SUCCESS;
  }
}
